<?php
class mdl_other_friends extends ujn_model {
	public function getRows($limit = 10) {
		$_sql = "SELECT * FROM {$this->tbl_name} LIMIT $limit";
		return $this->_db->getAll($_sql);
	}
	
	public function saveRow($mid, $friends) {
		if(!$mid = tls_func::uint($mid)) {
			return false;
		}
		$friends = json_encode($friends);
		
		$_sql = "INSERT INTO {$this->tbl_name} SET mid = '{$mid}', friends_str = '{$friends}'";
		$this->_db->query($_sql);
		
		return true;
	}
	
	public function deleteRows($mids) {
		$delMids = array();
		foreach((array)$mids as $k => $mid) {
			$mid = tls_func::uint($mid);
			$delMids[$mid] = $mid;
		}
		if(count($delMids) <= 0) return false;
		
		$_sql = "DELETE FROM {$this->tbl_name} WHERE mid in (" . implode(',', $delMids) . ")";
		$this->_db->query($_sql);
		
		return true;
	}
	
	
	protected function __construct() {
		parent::__construct();
		$this->db_name		= 'love_a_love';
		$this->tbl_name		= "`{$this->db_name}`.`love_friends`";
		$this->_db			= $this->mysql();
	}


    /**
     * 单例模型
     * @return mdl_other_friends
     */
	static function getInstance() {
        return parent::getInstance(__CLASS__);
	}	
}